package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.pojo.AppointmentServeListEntity;
import com.egg.ylt.pojo.AppointmentSubOrderEntity;
import com.egg.ylt.pojo.TechnicianEntity;
import com.egg.ylt.presenter.IShopAppintPresenter;
import com.egg.ylt.view.IShopAppointmentView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.util.HashMap;

/**
 * Created by sichaoqi on 2018/8/29.
 */

public class ShopAppoinPresenterImpl extends BasePresenter<IShopAppointmentView> implements IShopAppintPresenter {
    @Override
    public void setAppoinInfo(String token, String companyId, String name, String phone, final String remark,
                              String appointmentTime, String gender, final String shopId, String serviceId,
                              final String serviceName,
                              String price, String teacherId, final String teacherName) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("companyId", companyId);
        hashMap.put("name", name);
        hashMap.put("phone", phone);
        hashMap.put("remark", remark);
        hashMap.put("appointmentTime", appointmentTime);
        hashMap.put("gender", gender);
        hashMap.put("shopId", shopId);
        hashMap.put("serviceId", serviceId);
        hashMap.put("serviceName", serviceName);
        hashMap.put("price", price);
        hashMap.put("teacherId", teacherId);
        hashMap.put("teacherName", teacherName);
        RequestManager.getInstance().requestPostByAsyn(API.POST_ADD_APPOINTMENT, hashMap,
                new ReqCallBack<AppointmentServeListEntity.ListEntity>() {

                    @Override
                    public void onReqSuccess(AppointmentServeListEntity.ListEntity entity) {
                        mView.dismissDialogLoading();
                        entity.setShopId(shopId);
                        mView.setAppointmentSucceed(entity);
                    }

                    @Override
                    public void onFailure(String result) {
                        mView.dismissDialogLoading();
//                mView.showError(result);
                        CommonUtils.makeEventToast(mContext, result, false);
                    }

                    @Override
                    public void onReqFailed(ErrorBean error) {
                        mView.dismissDialogLoading();
//                mView.showException(error.toString());
                        CommonUtils.makeEventToast(mContext, error.getMsg(), false);
                    }
                });
    }

    @Override
    public void getTechnicianStatus(String token, String appointmentTime, String shopId, String serviceId) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("appointmentTime", appointmentTime);
        hashMap.put("shopId", shopId);
        hashMap.put("serviceId", serviceId);

        RequestManager.getInstance().requestPostByAsyn(API.GET_TECHNICIAN_STATUS, hashMap,
                new ReqCallBack<TechnicianEntity>() {

                    @Override
                    public void onReqSuccess(TechnicianEntity entity) {
                        mView.dismissDialogLoading();
                        mView.setTechnician(entity == null ? null : entity.getList());
                    }

                    @Override
                    public void onFailure(String result) {
                        mView.dismissDialogLoading();
                        CommonUtils.makeEventToast(mContext, result, false);
                    }

                    @Override
                    public void onReqFailed(ErrorBean error) {
                        mView.dismissDialogLoading();
                        CommonUtils.makeEventToast(mContext, error.getMsg(), false);
                    }
                });
    }

    @Override
    public void getSubOrderById(String token, String orderId) {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("orderId", orderId);

        RequestManager.getInstance().requestPostByAsyn(API.GET_APPOINTMENT_SUB_ORDER_BY_ID, hashMap,
                new ReqCallBack<AppointmentSubOrderEntity>() {

                    @Override
                    public void onReqSuccess(AppointmentSubOrderEntity entity) {
                        mView.dismissDialogLoading();
                        mView.setAppointmentSubOrderData(entity);
                    }

                    @Override
                    public void onFailure(String result) {
                        mView.dismissDialogLoading();
                        CommonUtils.makeEventToast(mContext, result, false);
                    }

                    @Override
                    public void onReqFailed(ErrorBean error) {
                        mView.dismissDialogLoading();
                        CommonUtils.makeEventToast(mContext, error.getMsg(), false);
                    }
                });
    }
}
